package org.iteam.xlz.core.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.iteam.commons.utils.DateUtil;
import org.iteam.core.utils.SqlBuilder;
import org.iteam.db.BaseService;
import org.iteam.xlz.core.entity.log.LogCreator;

public class LogCreatorService extends BaseService<LogCreator>{
	private LogCreatorService(){}
	
	private static LogCreatorService instance;
	
	public static LogCreatorService getInstance(){
		if(null==instance){
			instance=new LogCreatorService();
		}
		return instance;
	}
	
	
	public List<LogCreator> query(long page,long rows){
		try {
			return super.query("select * from logcreator where 1=1 order by createtime desc limit ?,?",(page-1)*rows,rows);
		} catch (SQLException e) {
			e.printStackTrace();
			return new ArrayList<LogCreator>();
		}
	}
	
	public long counts(){
		try {
			return super.counts("select count(1) from logcreator where 1=1");
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	public boolean create(LogCreator model){
		SqlBuilder sql=SqlBuilder.createInsert("logcreator");
		sql.addField("logid",UUID.randomUUID().toString().replace("-",""));
		sql.addField("creator",model.getCreator());
		sql.addField("logtype",model.getLogtype());
		sql.addField("logcontent",model.getLogcontent());
		sql.addField("createtime",DateUtil.currentTime());
		try {
			return super.updates(sql.getSql(),sql.getParams())==1;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
	}
}
